package cn.yj.core.business.controller;

import cn.yj.cgs.dba.entity.Swiper;
import cn.yj.admin.frame.AbstractController;
import cn.yj.core.business.service.SwiperService;
import cn.yj.entity.R;
import cn.yj.syslog.common.LogType;
import cn.yj.syslog.common.OperateLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author 永健
 * @since 2021-06-20 15:02
 */
@RestController
@RequestMapping("/swiper")
public class SwiperController extends AbstractController<Swiper> {

    @Resource
    private SwiperService swiperService;

    @Override
    @GetMapping("/pageList")
    @RequiresPermissions("swiper:list")
    public R pageList(@RequestParam Map<String, Object> params) {
        return success(swiperService.pageList(params, page()));
    }

    @RequiresPermissions("swiper:list")
    @GetMapping("/listChoose")
    public R listChoose() {
        return success(swiperService.listChoose());
    }


    @RequiresPermissions("swiper:choose:add")
    @PostMapping("/removeChoose/{ids}")
    @OperateLog(describe = "移除轮播图",type = LogType.UPDATE)
    public R removeChoose(@PathVariable Integer[] ids) {
        return result(swiperService.removeChoose(ids));
    }

    @RequiresPermissions("swiper:choose:del")
    @PostMapping("/setChoose/{ids}")
    @OperateLog(describe = "选择轮播图",type = LogType.UPDATE)
    public R setChoose(@PathVariable Integer[] ids) {
        return result(swiperService.setChoose(ids));
    }

    @DeleteMapping("/delete/{ids}")
    @OperateLog(describe = "删除轮播图",type = LogType.DELETE)
    @RequiresPermissions("swiper:del")
    public R remove(@PathVariable Integer[] ids) {
        return result(swiperService.removeById(ids));
    }

    @PostMapping("/save")
    @OperateLog(describe = "添加轮播图",type = LogType.INSERT)
    @RequiresPermissions("swiper:add")
    public R save(@RequestBody Swiper swiper) {
        return result(swiperService.save(swiper));
    }

}
